package com.zoroki.student_score_system.controller;



import com.zoroki.student_score_system.domain.Major;
import com.zoroki.student_score_system.domain.Major;
import com.zoroki.student_score_system.service.CourseService;
import com.zoroki.student_score_system.service.MajorService;
import com.zoroki.student_score_system.utils.Msg;
import com.zoroki.student_score_system.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/major")
public class MajorController {
    @Autowired
    MajorService majorService;


    @GetMapping("/findAllMajor")
    public @ResponseBody Result<List<Major>> findAllMajor() {
        return new Result<List<Major>>(0,majorService.findAllMajor(), Msg.SUCCESS);
    }

    @GetMapping("/findMajorById")
    public @ResponseBody Result<Major> findMajorById(int id) {
        return new Result<Major>(0,majorService.findMajorById(id), Msg.SUCCESS);
    }


    @PostMapping("/addMajor")
    public @ResponseBody Result<Boolean> addMajor(@RequestBody Major major) {
        return new Result<Boolean>(0,majorService.addMajor(major), Msg.SUCCESS);
    }

    @PostMapping("/updateMajor")
    public @ResponseBody Result<Boolean> updateMajor(@RequestBody Major Major) {
        return new Result<Boolean>(0,majorService.updateMajor(Major), Msg.SUCCESS);
    }

    @PostMapping("/deleteMajor")
    public @ResponseBody Result<Boolean> deleteMajor(int id) {
        return new Result<Boolean>(0,majorService.deleteMajor(id), Msg.SUCCESS);
    }

}
